﻿using System.Text.RegularExpressions;

namespace LiveHub.DataModels;

public partial class BlockMessage : IMessageItem
{
    public List<IMessageItem> Items { get; } = [];
    public string Content { get; }

    public BlockMessage(string content)
    {
        Content = content;
        foreach (var item in BlockRegex().Split(content))
        {
            if (item.StartsWith('@'))
            {
                Items.Add(new AtMessage() { Content = item });
            }
            else if (item.StartsWith("**"))
            {
                Items.Add(new BoldMessage() { Content = item.Replace("**", "") });
            }
            else if (item.StartsWith('*'))
            {
                Items.Add(new ItalicMessage() { Content = item.Replace("*", "") });
            }
            else if (item.StartsWith("__"))
            {
                Items.Add(new UnderlineMessage() { Content = item.Replace("__", "") });
            }
            else
            {
                Items.Add(new StringMessage() { Content = item });
            }
        }
    }

    [GeneratedRegex(@"(@.*?\s)|(\*\*.*?\*\*)|(\*.*?\*)|(__.*?__)")]
    private static partial Regex BlockRegex();
}

public class ItalicMessage : IMessageItem
{
    public string Content { get; init; } = "";
}

public class UnderlineMessage : IMessageItem
{
    public string Content { get; init; } = "";
}

public class BoldMessage : IMessageItem
{
    public string Content { get; init; } = "";
}

public class StringMessage : IMessageItem
{
    public string Content { get; init; } = "";
}

public class AtMessage : IMessageItem
{
    public string Content { get; init; } = "";
}

public interface IMessageItem;